/**
 * @author of2198
 * @date 2017/4/26.
 * @description
 */

import { Actor, Action } from "iflux2";
import { Map, List, fromJS } from "immutable";

export default class TemplateActor extends Actor {
  defaultState() {
    return {
      templateList: fromJS({
        pc: {},
        weixin: {},
        app: {}
      }),
      pageTypeTab: List(),
      platformTab: List(),
      totalCount: 0,
      pageTypeCount: 0,
      activatedPageInfo: Map()
    };
  }

  @Action("SET_TEMPLATE_LIST")
  setTemplateList(state, templateInfo) {
    return state.update("templateList", templateList => {
      return templateList.update(templateInfo.platform, () =>
        fromJS(templateInfo.data)
      );
    });
    // .set('totalCount', templateInfo.totalCount);
  }

  @Action("SET_PLATFORM_BTN_LIST")
  setPlatformBtns(state, btnInfo) {
    return state.set("platformTab", fromJS(btnInfo.platformTabInfo));
  }

  @Action("SET_PAGE_TYPE_BTN_LIST")
  setPageTypeBtns(state, btnInfo) {
    return state.set("pageTypeTab", fromJS(btnInfo.pageTypeTabInfo));
  }

  @Action("SET_PAGE_TYPE_COUNT")
  setPageTypeCount(state, pageTypeCount) {
    return state.set("pageTypeCount", pageTypeCount);
  }

  @Action("SET_ACTIVATED_PAGE_INFO")
  setActivatedPageInfo(state, activatedPage) {
    return state.set("activatedPageInfo", fromJS(activatedPage));
  }
}
